
<template>
  <div>
    <SearchForm
        @search="onSearch"
        @reset="onReset"
        :search-list="searchList" :search-params="searchParams">
    </SearchForm>

    <div class="table-layout">
      <el-card shadow="never">
<!--        <div class="table-handle">-->
<!--          <el-button type="primary" size="mini" icon="el-icon-plus" @click="onAdd">新增</el-button>-->
<!--        </div>-->
        <div class="table-box">
          <el-table
              size="large"
              stripe
              border
              v-loading="loading"
              max-height="500px"
              :data="tableData"
              element-loading-spinner="el-icon-loading"
              element-loading-background="rgba(255, 255, 255, 0.8)"
              @selection-change="onSelect"
          >
            <el-table-column show-overflow-tooltip align="center" v-for="item in columns" :key="item.prop" :prop="item.prop" :label="item.label">
              <template slot-scope="scope">
                <template v-if="item.type === 'select'">
                  <el-tag :type="item.tagType" v-if="item.isTag">{{ item.mapping[scope.row[item.prop]] }}</el-tag>
                  <span v-else>{{ item.mapping[scope.row[item.prop]] }}</span>
                </template>
                <span v-else>{{ scope.row[item.prop] }}</span>
              </template>
            </el-table-column>
            <el-table-column label="是否查看" width="120px" align="center">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.is_read === 1" type="success">是</el-tag>
                <el-tag v-if="scope.row.is_read === 0" type="info">否</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="操作" fixed="right" width="150px">
              <template slot-scope="scope">
                <el-button type="text" style="color: #F82222" @click="onDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="page-box">
          <el-pagination
              background
              :current-page="pageNo"
              :page-sizes="pageSizes"
              :page-size="pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalSize"
              @size-change="changePageSize"
              @current-change="changePageNo"
          />
        </div>
      </el-card>
    </div>
    <Add ref="addFormRef" @get-page="initData" />
  </div>
</template>
<script>

import crud from "@/mixins/crud";
import { http } from "@/api";
import Add from "./add";
export default {
  name: "index",
  components: {
    Add
  },
  mixins: [crud],
  data() {
    return {
      request: http.postJoin,
      defaultParams: {
        post_id: this.$route.query.id
      },
      searchList: [
        {
          label: '企业',
          prop: 'company_user_id',
          name: 'select',
          clearable: true,
          options: [],
        },
      ],
      searchParams: {
        company_user_id: ''
      },
      columns: [
        { prop: 'companyName', label: '所属企业' },
        { prop: 'category', label: '发布类别' },
        { prop: 'name', label: '职位名称' },
        { prop: 'nickname', label: '投递人' },
        { prop: 'phone', label: '投递人联系电话' },
        { prop: 'sex', label: '性别' },
        { prop: 'nickname', label: '身高' },
        { prop: 'desc', label: '自我评价' },
        { prop: 'create_time', label: '创建时间' },
      ],
      tableData: [

      ]
    }
  },
  created() {
    http.user.list().then(res => {
      this.searchList[0].options = res.data.map(item => {
        return {
          label: item.company_name,
          value: item.id
        }
      })
    })
  },
  methods: {
    formatTableData(data) {
      data.forEach(item => {
        if (item.company) {
          item.companyName = item.company.company_name
        }
        if(item.post) {
          item.category = item.post.category
          item.name = item.post.name
        }
        if (item.resume) {
          item.nickname = item.resume.nickname
          item.phone = item.resume.phone
          item.sex = item.resume.sex
          item.height = item.resume.height
          item.desc = item.resume.desc
        }
      });
    },
  }
}
</script>

<style scoped lang="scss">

</style>
